package com.luck.service;

import com.luck.dto.InventoryDao;
import com.luck.dto.OrderingDTO;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StockService {

    @Autowired
    private InventoryDao inventoryDao;

    @GlobalTransactional(name="createOrder-lk")
    public String freeze(OrderingDTO dto) {
        dto.getProducts().forEach(p->{
            inventoryDao.deduct(p.getProductId(),p.getQty());
        });

        return "ok";
    }
}